import React, { useState } from 'react'
import { LineStyled, ButtSub ,ImgInput } from '../../components/informations'

import DataDemo from './informationsDate'

import A from 'assets/images/my/touxiang2@2x.png'
import B from 'assets/images/my/wd_next@2x.png'
const Line = function (props) {
    // console.log(props.list.data)
        const [uName, setUname] = useState('')
        const [realName, setRealname] = useState('')
        const [phone, setPhone] = useState('')
        const [imgValue, setImgValue] = useState('')
        // props.list.data?setUname(props.list.data.uname):''
        console.log(uName)
    return (
        <>

          <LineStyled><em>头像</em><ImgInput> <img src={props.imgInput?props.imgInput:(props.list.data?'http://laienli.cn:8080/Legang'+props.list.data.himg:A)} alt="" /><input type="file" onChange={e=>{setImgValue(e.target.files[0]); props.changeItem(e)}}/></ImgInput></LineStyled>
            <LineStyled><em>昵称</em><input type="text" placeholder={props.list.data&&props.list.data.uname!==''?props.list.data.uname:'请输入2-6个字符'} value={uName || ''} onChange={(e) => setUname(e.target.value)} /></LineStyled>
            <LineStyled><em>真实姓名</em><input type="text" placeholder={props.list.data&&props.list.data.realname!==''?props.list.data.realname:'请输入您的正确姓名'} value={realName || ''} onChange={(e) => setRealname(e.target.value)} /></LineStyled>
            <LineStyled><em>手机号</em><input type="text" placeholder={(props.list.data&&props.list.data.phone!=='')?props.list.data.phone:'请输入正确手机号'} value={phone || ''} onChange={(e) => setPhone(e.target.value)} /></LineStyled>
            <DataDemo></DataDemo>
            <ButtSub onClick={informationpush.bind(false, uName, realName, phone,props.uid,imgValue,props)}>保存</ButtSub>
        </>
    )
}
async function informationpush(a, b, c,e,f,g) {
    console.log(a)
    var formData = new FormData();
    formData.append('headimg', f)
    formData.append('uname',a)
    formData.append('realname',b)
    formData.append('phone',c)
    formData.append('uid',e)

    // console.log(formData)
    let d = await fetch('/Legang/user/updateuser',{
        method:'POST',
        body:formData,
        header:{"Content-Type": "multipart/form-data"}
    }).then(response=>response).then(res=>res)
    g.props.history.go(-1)
    
}

export default Line

